package com.study.d015propertybind.fx;

import javafx.beans.property.SimpleMapProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.MapChangeListener;
import javafx.collections.ObservableMap;

/**
*@description
*@author xtayhame
*date 2020年3月5日
*version
*since v1.0
*/
public class SimpleMapPropertyMain {
	public static void main(String[] args) {
		ObservableMap<String, String> map=FXCollections.observableHashMap();
		map.put("1", "A");
		map.put("2", "B");
		map.put("3", "C");

		SimpleMapProperty<String, String> mapProperty= new SimpleMapProperty<>(map);

		mapProperty.addListener(new ChangeListener<ObservableMap<String, String>>() {

			@Override
			public void changed(ObservableValue<? extends ObservableMap<String, String>> observable,
					ObservableMap<String, String> oldValue, ObservableMap<String, String> newValue) {
				System.out.println("oldValue="+oldValue);
				System.out.println("newValue="+newValue);
			}
		});

		mapProperty.addListener(new MapChangeListener<String, String>() {

			@Override
			public void onChanged(
					javafx.collections.MapChangeListener.Change<? extends String, ? extends String> change) {
				ObservableMap map =change.getMap();
			}
		});

		mapProperty.put("4", "D");
	}
}
